package org.niugang.controller;

import org.apache.commons.lang3.StringUtils;
import org.niugang.annotation.LogApi;
import org.niugang.bean.UserQueryBean;
import org.niugang.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 * Copyright: Copyright (c) 2018 863263957@qq.com
 * 
 * @ClassName: UserController.java
 * @version: v1.0.0
 * @author: niugang
 * @date: 2018年9月19日 下午5:02:16
 */
@RestController
@RequestMapping("userservice")
public class UserController {

	@Autowired
	private UserService userService;

	/**
	 * 测试日志发送到rabbitmq
	 * 
	 * @return
	 */
	@GetMapping("logs")
	@LogApi(value = "日志测试")
	public String logs() {
		return "success";
	}

	@GetMapping("user")
	@LogApi(value = "获取用户信息")
	public String getUserInfo() {
		return "张三";
	}

	/**
	 * 注册
	 * @return
	 */
	@PostMapping("user")
	@LogApi(value = "注册用户")
	public ResponseEntity<Object> regist(@RequestBody UserQueryBean user) {
		if (StringUtils.isBlank(user.getAccount()) || StringUtils.isBlank(user.getPassword())
				|| StringUtils.isBlank(user.getName())) {
			return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(HttpStatus.BAD_REQUEST.getReasonPhrase());
		}
		userService.insert(user);
		return ResponseEntity.status(HttpStatus.OK).body(HttpStatus.OK.getReasonPhrase());
	}

}
